<?php

/*
	满意
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['statuss']=$this->work_status;
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	//类型。1表示开发日志，2表示bug修复日志，3表示客户异常问题处理
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(!empty($_RQ['workermid'])){
		$params['workerid']=intval($_RQ['workerid']);
		$return['params']['workerid']=$_RQ['workerid'];
	}
	//日志名称
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	
	$orderby='id desc';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_workliu_survey',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($list as &$row){
		$row['member']=cfc('core')->member_show($row['mid']);
		$row['worker']=cfc('core')->member_show($row['workermid']);
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'日志列表'),
		),
		'list'=>array('data'=>'list','tip'=>'','delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'star','title'=>'星数','type'=>'star','set'=>'star'),
			array('name'=>'member','title'=>'客户','type'=>'member'),
			array('name'=>'worker','title'=>'所属员工','type'=>'member'),
			array('name'=>'msg','title'=>'内容','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>13,'title'=>'选择员工','name'=>'workermid','action'=>'jy_scrm/worker.get_worker/'),
		),
	);
	$return['htmls']=$htmls;
	$return['groups']=pdo_getall('jy_workliu_workgroup',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['fankui_types']=$this->fankui_types;
	$return['work_status']=$this->work_status;
	$return['wentigroup']=pdo_getall('jy_workliu_wentigroup',array('status'=>1,'uniacid'=>$_SESSION['uniacid']));

	exi($return);
}
if($_RQ['op']=='look'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择日志！','error');
	}
	$item=pdo_get('jy_workliu_survey',array('id'=>$id));
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'look',
		'desc'=>'日志详情',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回列表'),
		),
		'look'=>array(
			array('name'=>'title','title'=>'日志名称','type'=>'string'),
			array('name'=>'kehuname','title'=>'客户简称','type'=>'string'),
			array('name'=>'msg','title'=>'日志内容','type'=>'string'),
			array('name'=>'workgroupid','title'=>'日志分类','type'=>'select','options'=>'groups'),
			array('name'=>'status','title'=>'日志状态','type'=>'radio','options'=>'work_status'),
			array('name'=>'fankui_type','title'=>'反馈方式','type'=>'radio','options'=>'fankui_types'),
			array('name'=>'wenti_type','title'=>'问题类型','type'=>'select','options'=>'groups'),
		),
	);
	$return['groups']=pdo_getall('jy_workliu_workgroup',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['fankui_types']=$this->fankui_types;
	$return['work_status']=$this->work_status;
	$return['wentigroup']=pdo_getall('jy_workliu_wentigroup',array('status'=>1,'uniacid'=>$_SESSION['uniacid']));

	exi($return);
}
if($_RQ['op']=='star'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('参数错误！','error');
	}
	$update=array();
	$post=get_postdata();
	if(isset($post['star'])){
		$update['star']=$post['star'];
	}
	if($update){
		pdo_update('jy_workliu_survey',$update,array('id'=>$id));
	}
	exi('操作成功！');
}
//添加编辑日志
if($_RQ['op']=='edit'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array(
			'title'=>trim($post['title']),
			'groupid'=>intval($post['groupid']),
			'content'=>trim($post['content']),
			'image'=>ijson_encode($post['image']),
			'workerid'=>intval($post['workerid']),
			'credit'=>intval($post['credit']),
			'type'=>intval($post['type']),
			'jiaji'=>intval($post['jiaji']),
		);
		if($post['workerid']){
			$data['receive_type']=1;
			$data['receive_time']=TIMESTAMP;
		}
		$id=intval($post['id']);
		if($id){
			pdo_update('jy_workliu_survey',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		}else{
			$data['createtime']=TIMESTAMP;
			$data['uniacid']=$_SESSION['uniacid'];
			pdo_insert('jy_workliu_survey',$data);
		}
		exi('操作成功！','','list');
	}
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_workliu_survey',array('id'=>$id));
	}else{
		$item=array();
	}
	$return['groups']=pdo_getall('jy_workliu_workgroup',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回日志列表'),
		),
		'desc'=>'设置日志信息',
		'edit'=>array(
			array('name'=>'title','title'=>'日志名称','type'=>'string'),
			array('name'=>'member','title'=>'所属员工','type'=>'member'),
			array('name'=>'workgroupid','title'=>'日志分类','type'=>'select','options'=>'groups'),
			array('name'=>'status','title'=>'日志状态','type'=>'radio','options'=>'work_status'),
			array('name'=>'fankui_type','title'=>'反馈方式','type'=>'radio','options'=>'fankui_types'),
			array('name'=>'wenti_type','title'=>'问题类型','type'=>'select','options'=>'groups'),
		),
	);
	$return['groups']=pdo_getall('jy_workliu_workgroup',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['fankui_types']=$this->fankui_types;
	$return['work_status']=$this->work_status;
	$return['wentigroup']=pdo_getall('jy_workliu_wentigroup',array('status'=>1,'uniacid'=>$_SESSION['uniacid']));

	exi($return);
}